import request from '@/config/axios'

export interface HistoryDo {
  id: string
  flowId: string
  userId: number
  subject: string
  tenantId: number
  createTime: number | string
}

// Chunk 数据结构
export interface ChunkItem {
  node: string
  content: string | null
  data: any
  status: string
}

export interface ChatDo {
  id: string
  role: 'user' | 'ai'
  atTime: number | null
  chunk: ChunkItem[] | null
  content: string | null
  hisId: string
  flowId: string
  flowCode: string | null
  userId: number
  files: string[] | null
  fileNames: string[] | null
}

export interface PageResultHistoryDo {
  list: HistoryDo[]
  total: number
}

export interface PageParam {
  pageNo: number
  pageSize: number
}

export interface AIChatPageReqVO extends PageParam {
  userId?: number
  subject?: string
  createTime?: string[]
}

// 查询AI对话历史记录分页
export const getAIChatHistoryPage = async (params: AIChatPageReqVO): Promise<PageResultHistoryDo> => {
  return await request.post({
    url: '/agent/blue-print/userChatHistory',
    data: {
      pageNo: params.pageNo,
      pageSize: params.pageSize,
      userId: params.userId
    }
  })
}

// 查询聊天历史中消息列表
export const getChatHistory = async (hid: string): Promise<ChatDo[]> => {
  return await request.get({
    url: `/agent/blue-print/chatHistory/${hid}`
  })
} 
